package org.example.service.impl;


import lombok.extern.slf4j.Slf4j;
import org.example.domain.CabinetMachine;
import org.example.domain.ExpressPackage;
import org.example.domain.ExpressVo;
import org.example.mapper.ExpressPackageMapper;
import org.example.service.IExpressPackageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 包裹Service业务层处理
 *
 * @author ruoyi
 * @date 2024-08-26
 */
@Service
@Slf4j
public class ExpressPackageServiceImpl implements IExpressPackageService {
    @Autowired
    private ExpressPackageMapper expressPackageMapper;

    /**
     * 查询包裹
     *
     * @param id 包裹主键
     * @return 包裹
     */
    @Override
    public ExpressPackage selectExpressPackageById(Long id) {
        return expressPackageMapper.selectExpressPackageById(id);
    }

    /**
     * 查询包裹列表
     *
     * @return 包裹
     */
    @Override
    public ExpressVo selectExpressPackageList(Long deliveryid){
        List<ExpressPackage> expressPackages = expressPackageMapper.selectExpressPackageList(deliveryid);
        ExpressVo expressVo = new ExpressVo();
        List<List<ExpressPackage>> lists = new ArrayList<>();
        Integer[] arrays = {3,1,6};
        for (Integer i:arrays){
            if (expressPackages.size()!=0){
                List<ExpressPackage> list = expressPackages.stream()
                        .filter(e -> e.getStatus()==i).collect(Collectors.toList());
                lists.add(list);
            }
        }
        log.info("lists:{}",lists);
        expressVo.setList(lists);
        return expressVo;
    }

    @Override
    public List<CabinetMachine> findCabinetMachine(Integer id) {
        return expressPackageMapper.findCabinetMachine(id);
    }
}
